home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Cinema 4D GO demo / Gumption Plug-ins / Plug-ins / Freeware / Find And Replace / FindAndReplace.cof
Text File  |  1998-03-18  |  947b  |  52 lines

  1. // Search for all objects with a specific string and replace
  2. // part of the name with a new one
  3. // (c) Christian Losch 1997
  4. // Maxon Computer GmbH
  5.  
  6. DoIt(op,s1,s2)
  7. {
  8.     var s3,pos;
  9.     while (op)
  10.     {
  11.         s3 = op->GetName();
  12.         pos = strstr(s3,s1);
  13.  
  14.         if (pos>=0)
  15.         {
  16.             var t1,t2,t3,len,ll;
  17.             len = sizeof(s3);
  18.             ll  = sizeof(s1);
  19.  
  20.             if (pos>0) t1 = strmid(s3,0,pos-1); else t1="";
  21.             t2 = s2;
  22.             if (len-(pos+ll)>0) t3 = strmid(s3,pos+ll,len-(pos+ll)); else t3="";
  23.  
  24.             op->SetName(stradd(t1,t2,t3));
  25.         }
  26.         DoIt(op->GetDown(),s1,s2);
  27.         op = op->GetNext();
  28.     }
  29. }
  30.  
  31.  
  32.  
  33. Function(doc)
  34. {
  35.     var op,dlg = new (SimpleDialog);
  36.  
  37.  
  38.     dlg->SetTitle("Find and Replace 2");
  39.     dlg->SetData(0,"Find   ",FIELD_STRING,0.0,0.0,"");
  40.     dlg->SetData(1,"Replace",FIELD_STRING,0.0,0.0,"");
  41.  
  42.     if (!dlg->DoDialog()) return;
  43.  
  44.     DoIt(doc->GetFirstObject(),dlg->GetData(0),dlg->GetData(1));
  45.  
  46.     doc->SendMessage(DOCUMENT_CHANGED);
  47. }
  48.  
  49. main()
  50. {
  51.     RegisterMenuHook("Find and Replace","Function");
  52. }